﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Projekt.Models.Primitives
{
    public class Dimension
    {
        VertexPositionColor[] vertices;
        private GraphicsDevice graphicsDevice;
        BasicEffect basicEffect;

        public Dimension(GraphicsDevice graphicsDevice, Vector3 Position, Vector3 Rotation, float radius)
        {
            this.graphicsDevice = graphicsDevice;

            vertices = new VertexPositionColor[6];
            vertices[0].Position = new Vector3(Position.X + (-1 * radius), Position.Y, Position.Z);
            vertices[0].Position = Vector3.Transform(vertices[0].Position, Matrix.CreateFromYawPitchRoll(Rotation.Y, Rotation.X, Rotation.Z));
            vertices[0].Color = Color.DarkRed;
            vertices[1].Position = new Vector3(Position.X + (1 * radius), Position.Y, Position.Z);
            vertices[1].Position = Vector3.Transform(vertices[1].Position, Matrix.CreateFromYawPitchRoll(Rotation.Y, Rotation.X, Rotation.Z));
            vertices[1].Color = Color.Red;
            vertices[2].Position = new Vector3(Position.X, Position.Y + (-1 * radius), Position.Z);
            vertices[2].Position = Vector3.Transform(vertices[2].Position, Matrix.CreateFromYawPitchRoll(Rotation.Y, Rotation.X, Rotation.Z));
            vertices[2].Color = Color.DarkGreen;
            vertices[3].Position = new Vector3(Position.X, Position.Y + (1 * radius), Position.Z);
            vertices[3].Position = Vector3.Transform(vertices[3].Position, Matrix.CreateFromYawPitchRoll(Rotation.Y, Rotation.X, Rotation.Z));
            vertices[3].Color = Color.Green;
            vertices[4].Position = new Vector3(Position.X, Position.Y, Position.Z + (-1 * radius));
            vertices[4].Position = Vector3.Transform(vertices[4].Position, Matrix.CreateFromYawPitchRoll(Rotation.Y, Rotation.X, Rotation.Z));
            vertices[4].Color = Color.DarkBlue;
            vertices[5].Position = new Vector3(Position.X, Position.Y, Position.Z + (1 * radius));
            vertices[5].Position = Vector3.Transform(vertices[5].Position, Matrix.CreateFromYawPitchRoll(Rotation.Y, Rotation.X, Rotation.Z));
            vertices[5].Color = Color.Blue;

            basicEffect = new BasicEffect(graphicsDevice);
            basicEffect.VertexColorEnabled = true;
        }

        public void Draw(Matrix View, Matrix Projection)
        {
            basicEffect.Projection = Projection;
            basicEffect.View = View;

            basicEffect.CurrentTechnique.Passes[0].Apply();

            graphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineList, vertices, 0, 3);
        }
    }
}
